package com.ioc.service;

import com.ioc.dao.BookDao;
import com.ioc.dao.UserDao;
import com.ioc.dao.impl.UserDaoImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Autowired:根据类型注入，@Autowired+@Qualifier 根据名称注入
 * @Resource:根据类型注入,@Resource(name='xx')根据名称注入
 *
 *
 */
//@Component
@Service("userService")
public class UserService {


    @Autowired//根据类型注入
    @Qualifier("userDao")//让autowire自动装配的时候根据名称装配
    private UserDao userDao;

    @Resource//如果写了名称就根据名称注入，如果没有写名称，就根据类型自动装配
    private BookDao bookDao;


    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public void setBookDao(BookDao bookDao) {
        this.bookDao = bookDao;
    }

    public void save(){
        userDao.save();
        bookDao.save();
    }


}
